define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'track/index' + location.search,
                    add_url: 'track/add',
                    edit_url: 'track/edit',
                    del_url: 'track/del',
                    multi_url: 'track/multi',
                    import_url: 'track/import',
                    table: 'track',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
				searchFormVisible: true,
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),operate:false},
                        {field: 'cooperation.cname', title: __('Project'), operate: 'LIKE'},
                        //{field: 'cooperation_id', title: __('Cooperation_id')},
                        {field: 'admin.nickname', title: __('Initiator'), operate: 'LIKE'},
                        //{field: 'initiator_id', title: __('Initiator_id')},
                        {field: 'year', title: __('Year')},
                        {field: 'participating_departments', title: __('Participating_departments'), operate: 'LIKE'},
                        //{field: 'examinefile', title: __('Examinefile'), operate: false, formatter: Table.api.formatter.file},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        //{field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'endtime', title: __('Endtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        //{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate},
                        {
                            field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: "detail",
                                    icon: "fa fa-list",
                                    title: function (row, index) {
                                        //return __('Detail') + "[" + row['name'] + "]";
                                        return __('Detail');
                                    },
                                    text: __('Detail'),
                                    classname: "btn btn-xs btn-info btn-dialog",
                                    url: "trackdetail/index?track_id={ids}",
                                },
                                {
                                    name: "preview",
                                    icon: "fa fa-list",
                                    title: function (row, index) {
                                        //return __('Detail') + "[" + row['name'] + "]";
                                        return __('预览');
                                    },
                                    text: __('预览'),
                                    classname: "btn btn-xs btn-info btn-dialog",
                                    url: "track/previewWord?ids={ids}",
                                },
                                {
                                    name: "download",
                                    icon: "fa fa-list",
                                    title: function (row, index) {
                                        //return __('Detail') + "[" + row['name'] + "]";
                                        return __('下载');
                                    },
                                    text: __('下载'),
                                    classname: "btn btn-xs btn-info",
                                    url: "track/downloadWord?ids={ids}",
                                }
                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
